<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<link href="${pageContext.request.contextPath}/css/style.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/css/table.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/dwz/themes/default/style.css" rel="stylesheet" type="text/css" media="screen" />
<link href="${pageContext.request.contextPath}/dwz/themes/css/core.css" rel="stylesheet" type="text/css" media="screen" />
<script src="${pageContext.request.contextPath}/jquery/jquery-2.1.4.min.js"></script>
<table border="0" cellpadding="0" cellspacing="0" class="table_border">
	<tr>
		<td>
			<table width="100%" border="0" cellpadding="0" cellspacing="0"
				class="table_right">
				<tr>
					<td><font style="font-size: 12px;"><strong>修改用户</strong></font>
					</td>
					<td width="25" height="26" align="left"></td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td>
			<table width="100%" border="0" cellspacing="0" class="table_right">
				<tr>
					<td align="center">
						<table width="100%" border="0" cellspacing="0"
							class="table_padding">
							<tr>
								<td align="center">
									<table border="0" cellpadding="0" cellspacing="0"
										class="box_table" id="box_table2">
										<thead>
											<tr>
												<td class="box_table_even">登录帐号：</td>
												<td class="box_table_odd">
													<span class="in">
														<input type="text" value="${user.accountNo}" id="accountNo"/>
														<span class="star">*</span>
													</span>
												</td>
											</tr>
											<tr>
												<td class="box_table_even">用户姓名：</td>
												<td class="box_table_odd">
													<span class="in">
														<input type="text" value="${user.name}" id="name"/>
														<span class="star">*</span>
													</span>
												</td>
											</tr>
											<tr>
												<td class="box_table_even">电子邮件：</td>
												<td class="box_table_odd">
													<span class="in">
														<input type="text" value="${user.email}" id="email"/>
														<span class="star">*</span>
													</span>
												</td>
											</tr>
											<tr>
												<td class="box_table_even">登录密码：</td>
												<td class="box_table_odd">
													<span class="in">
														<input type="password" id="password" value="${user.password}" />
														<span class="star">*</span>
													</span>
												</td>
											</tr>
											<tr>
												<td class="box_table_even">密码确认：</td>
												<td class="box_table_odd">
													<span class="in">
														<input type="password" id="surePassword" value="${user.password}" onblur="surePassword(this.value)"/>
														<span class="star" >*</span>
														<span class="star" id="surePasswordMsg"></span>
													</span>
												</td>
											</tr>
											<tr>
												<td class="box_table_even">是否启用：</td>
												<td class="box_table_odd">

													<c:if test="${user.lockStatus==1}">
														<input type="radio" value="1" name="lock" checked/> 启用 <input type="radio" value="0" name="lock"/> 锁定
													</c:if>
													<c:if test="${user.lockStatus==0}">
														<input type="radio" value="1" name="lock"/> 启用 <input type="radio" value="0" name="lock" checked/> 锁定
													</c:if>

													<span class="star">*</span>
												</td>
											</tr>
											<tr>
												<td class="box_table_even">失效时间：</td>
												<td class="box_table_odd">
													<input type="text" value="${user.expireTime}" id="expireTime"/>
													<span class="star">*</span>
												</td>
											</tr>
											<tr>
												<td class="box_table_even">允许访问的IP：</td>
												<td class="box_table_odd">
													<span class="in">
														<input type="text" size="120" value="${user.allowIps}" id="allowIps"/>
													</span>
												</td>
											</tr>
										</thead>
										<tbody>
										</tbody>
									</table>
								</td>
							</tr>
						</table>

						<table border="0" cellpadding="0" cellspacing="0"
							class="operation">
							<thead>
								<tr>
									<td height="24">&nbsp;</td>
								</tr>
							</thead>
						</table>
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td>
			<table width="100%" border="0" cellpadding="0" cellspacing="0"
				class="table_padding">
				<tr>
					<td height="21" align="right">
						<table align="left">
							<tr>
								<td width="50px"><a class="button" href="javascript:void(0)" onclick="update()"><span>更新</span></a></td>
								<td width="50px"><a class="button"
									href="javascript:void(window.history.back());"><span>返回</span></a></td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
<script>
	/**
	 *
	 * 更新密码
	 * */
	function update() {
		let accountNo = $("#accountNo").val();
		let name = $("#name").val();
		let email = $("#email").val();
		let password = $("#password").val();
		let lock = $(":radio[name='lock']:checked").val();
		let expireTime = $("#expireTime").val();
		let allowIps = $("#allowIps").val();

		let json = {}
		json.accountNo = accountNo;
		json.name = name;
		json.email = email;
		json.password = password;
		json.lockStatus = lock;
		json.expireTime = expireTime;
		json.allowIps = allowIps;
		json.id= '${user.id}'


		console.log(json)
		$.post("user?method=updateUser",json,result=>{
			if (result.code=="200"){
				alert("更新成功")
			}else {
				alert("更新失败")
			}
		},"json")

	}

	/**
	 * 重复密码 鼠标移开事件
	 * @param surePassword
	 */
	function surePassword(surePassword) {
		let password = $("#password").val();
		let msg = $("#surePasswordMsg");
		if (password!=surePassword){
			msg.text("重复密码相同,请确认2次密码")
		}else {
			msg.text("")
		}
	}
</script>
